<?
    cria_variaveis($_POST,$_GET,$_FILES);
    require_once("./classes/upload.php");
?>
    <title><?php echo $msg->get('TRANSPOSTA_MSG_01') ?></title>
    <p class="titulo" align="center"><?php echo $msg->get('TRANSPOSTA_MSG_02') ?></p>
    <p class="subtitulo" align="center"><?php echo $msg->get('TRANSPOSTA_MSG_03') ?></font></p>
    <p>
    <div class="tabbar">
        <ul>
        <li><a href="index.php?inc=transposta.php&modo=material"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material") echo " class=\"tabact\""; ?>><?php echo $msg->get('Material_Teorico') ?></a></li>
        <li><a href="index.php?inc=transposta.php&modo=exemplo"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") echo " class=\"tabact\""; ?>><?php echo $msg->get('Exemplos_Prontos') ?></a></li>
        <li><a href="index.php?inc=transposta.php&modo=teclado"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") echo " class=\"tabact\""; ?>><?php echo $msg->get('Entrada_Teclado') ?></a></li>
        <li><a href="index.php?inc=transposta.php&modo=cas"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "cas") echo " class=\"tabact\""; ?>>Scilab</a></li>
        </ul>
    </div>
    <div id="cas">
<?php
if (!isset($Calcular)) {
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material")
    {
        $uploads = new Upload();
        $uploads->Lista("matrizes");
    } else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") { //leitura de dados via banco de dados - modulo de exemplos e exercicios
        include "exibe_prob_matriz_transposta_xml.php";
    } else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "cas") {
        require_once("./classes/cas.php");
        $cas = new CAS();
        $cas->addParam("A = [ 1 2 3; 4 5 6 ]");
        $cas->addParam("A'");
        $cas->exec();
        $cas->disp();
    }else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") {
        if ((strlen(@$dim)==0) | ($dim<0))  { 
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=transposta.php>";
            echo $msg->get('TRANSPOSTA_MSG_04');
            echo "<input type=text size='2' maxlength='2' name=dim value=".($dim).">";
            echo "<br><br>";
            echo "<input type=hidden name=executar value=sim>";
            echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
            echo "</form>";
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=transposta.php>";
            echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
            echo "</form>";
        }
        elseif (!checaNumerico($dim))
        {
    ?>
            <p><font color="red"><?php echo $msg->get('Apenas_Dados_Numericos') ?></font></p>
            <p><input type="button" value="<?php echo $msg->get('Voltar') ?>" onclick="history.back()" class="button"></p>
    <?php
        }
        else  {
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=transposta.php>";
            echo $msg->get('TRANSPOSTA_MSG_04');
            echo "<input type=text size='2' maxlength='2' name=dim value=".($dim).">";
            echo "<br><br>";
            echo "<p align=left><font face=Arial>".$msg->get('TRANSPOSTA_MSG_05')."</font>";
            echo "<nobr>";
            for ($i=0; $i<$dim; $i++) {
                echo "<br><br>";
                for ($j=0; $j<$dim; $j++) {
                        echo "<input type=text name=A[".($i)."][".($j)."] maxlength=10 size=5 value=".($A[$i][$j]).">";
                } //end forj
            } //end fori
            echo "</nobr>";
            echo "<p>";
            echo "<input class=button type=submit name=Calcular value=".$msg->get('G_MSG_04').">";
            echo "<br>";
            echo "</form>";
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=transposta.php>";
            echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
            echo "</form>";
        } //end if
    }
} else {
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
        verificaBib($xml_file);
    if (!checaNumerico($dim) || !checaNumerico($A))
    {
?>
        <p><font color="red"><?php echo $msg->get('Apenas_Dados_Numericos') ?></font></p>
        <p><input type="button" value="<?php echo $msg->get('Voltar') ?>" onclick="history.back()" class="button"></p>
<?php
    }
    else
    {
        echo "<br>";
        echo $msg->get('TRANSPOSTA_MSG_04');
        echo " $dim";
        echo "<br><br>";
        echo "<p align=left><b>".$msg->get('TRANSPOSTA_MSG_05')."</b> <br>";
        echo "<table border=\"0\">";
        for ($i=0; $i<$dim; $i++) {
        echo "<tr>";
        for ($j=0; $j<$dim; $j++) {
            echo "<td align=\"center\" valign=\"center\" width=\"40\">".$A[$i][$j]."</td>";
        }
        echo "</tr>";
        }
        echo "<p>";
        echo "</table>";
        for ($i=0; $i<$dim; $i++) {
        for ($j=0; $j<$dim; $j++) {
            $B[$i][$j] = $A[$j][$i];
        }
        }
        echo "<p align=left><b>".$msg->get('TRANSPOSTA_MSG_07')."</b> <br>";
        echo "<table border=\"0\">";
        for ($i=0; $i<$dim; $i++) {
        echo "<tr>";
        for ($j=0; $j<$dim; $j++) {
            echo "<td align=\"center\" valign=\"center\" width=\"40\">".$B[$i][$j]."</td>";
        }
        echo "</tr>";
        }
        echo "</table>";
        if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
        {
            echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
            echo "<script language=\"javascript\" type=\"text/javascript\">\n";
            echo "function criarLinks(value) {\n";
            echo "document.exemplos.indice.value = value;\n";
            echo "document.exemplos.action = 'index.php?inc=transposta.php&modo=exemplo'\n";
            echo "document.exemplos.submit();\n";
            echo "}\n";
            echo "</script>";
            echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
            echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
            echo "<input type=\"hidden\" name=\"indice\">";
            echo "<br><br>".$msg->get('Outros_Exemplos')."<br>";
            $objeto = new DomDocument();
            $objeto->load($xml_file);
        //	$raiz = $objeto->document_element();
            $filho = $objeto->getelementsbytagname("matrices");
            if ($filho->length > 0)
            {
                $temp = $filho->item(0)->getelementsbytagname("matrix");
                $j = 0;
                for($i = 0; $i < $temp->length; $i++)
                {
                    $conteudo = $temp->item($i)->getelementsbytagname("dim");
                    if ($conteudo->length > 0)
                    {
                        if ($j != 0) echo " | ";
                        if ($j == $indice) echo "<b>";
                        echo "<a href=\"javascript:criarLinks($j)\" title=\"Dimens&atilde;o ".$conteudo->item(0)->nodeValue."\"><u>".($j+1)."</u></a>";
                        if ($j == $indice) echo "</b>";
                        $j++;
                    }
                }
            }
            echo "<br><Br>";
        }
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=transposta.php>";
        echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
        echo "</form>";
    }
}
?>
</div>